package com.inspur.edp.team.rest;


import com.inspur.edp.team.PaasEnvAuthorityService;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * 环境权限restful接口
 */
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)

public class EnvAuthorityController {


    private PaasEnvAuthorityService paasEnvAuthorityService = SpringBeanUtils.getBean(PaasEnvAuthorityService.class);

    /**
     * 删除成员环境权限
     *
     * @param envId
     * @param teamId
     * @param userId
     * @
     */
    @DELETE
    @Path(value = "/removeauthority/{envId}/{teamId}/{memberId}")
    public void removeAuthority(@PathParam("envId") String envId, @PathParam("teamId") String teamId, @PathParam("memberId") String userId) {
        paasEnvAuthorityService.removeAuthority(envId, teamId, userId);
    }

    /**
     * 团队与环境解绑，删除成员环境权限
     *
     * @param envId
     * @param teamId
     * @
     */
    @DELETE
    @Path(value = "/removeteamauthority/{envId}/{teamId}")
    public void removeTeamAuthority(@PathParam("envId") String envId, @PathParam("teamId") String teamId) {
        paasEnvAuthorityService.removeTeamAuthority(envId, teamId);
    }

    /**
     * 将成员移除团队，删除成员环境权限
     *
     * @param memberId
     * @param teamId
     * @
     */
    @DELETE
    @Path(value = "/removememberauthority/{teamId}/{memberId}")
    public void removeMemberAuthority(@PathParam("teamId") String teamId, @PathParam("memberId") String memberId) {
        paasEnvAuthorityService.removeMemberAuthority(teamId, memberId);
    }

    /**
     * 添加成员环境权限
     *
     * @param envId
     * @param teamId
     * @param userId
     */
    @POST
    @Path(value = "/addauthority/{envId}/{teamId}/{memberId}")
    public void addAuthority(@PathParam("envId") String envId, @PathParam("teamId") String teamId, @PathParam("memberId") String userId) {
        paasEnvAuthorityService.addAuthority(envId, teamId, userId);
    }

    /**
     * 添加团队环境权限
     *
     * @param envId
     * @param teamId
     * @
     */
    @POST
    @Path(value = "/addteamauthority/{envId}/{teamId}")
    public void addTeamAuthority(@PathParam("envId") String envId, @PathParam("teamId") String teamId) {
        paasEnvAuthorityService.addTeamAuthority(envId, teamId);
    }

    /**
     * 新增团队成员，添加环境权限
     *
     * @param userId
     * @param teamId
     * @
     */
    @POST
    @Path(value = "/addnewmemberauthority/{teamId}/{userId}")
    public void addNewMemberAuthority(List<String> envIdList,@PathParam("teamId") String teamId, @PathParam("userId") String userId) {
        paasEnvAuthorityService.addNewMemberAuthority(envIdList, teamId, userId);
    }


    /**
     * 获取拥有环境权限的成员信息
     *
     * @param envId
     * @param teamId
     */
    @GET
    @Path(value = "/authoritymemberlist/{envId}/{teamId}")
    public List<String> getAuthorityMemberlist(@PathParam("envId") String envId, @PathParam("teamId") String teamId) {
        return paasEnvAuthorityService.getAuthorityMemberlist(envId, teamId);
    }

    /*
    根据用户ID和团队ID校验用户是否为管理员
    */
    @GET
    @Path(value = "/checkauthority/{teamId}")
    public boolean editRoleCheck(@PathParam("teamId") String teamId){
        return paasEnvAuthorityService.editRoleCheck(teamId);
    }
}
